Public Class frmProductCategoryAdd
    Inherits System.Windows.Forms.Form
    Dim icg As frmProductCategoryView
#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents tbName As System.Windows.Forms.TextBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents tbCode As System.Windows.Forms.TextBox
    Friend WithEvents cmbLevel As DevComponents.DotNetBar.Controls.ComboBoxEx
    Friend WithEvents cmbWorld As DevComponents.DotNetBar.Controls.ComboBoxEx
    Friend WithEvents cmdSave As DevComponents.DotNetBar.ButtonX
    Friend WithEvents cmdExit As DevComponents.DotNetBar.ButtonX
    Friend WithEvents GroupPanel1 As DevComponents.DotNetBar.Controls.GroupPanel
    Friend WithEvents Label3 As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.tbName = New System.Windows.Forms.TextBox()
        Me.Label5 = New System.Windows.Forms.Label()
        Me.tbCode = New System.Windows.Forms.TextBox()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.cmbLevel = New DevComponents.DotNetBar.Controls.ComboBoxEx()
        Me.cmbWorld = New DevComponents.DotNetBar.Controls.ComboBoxEx()
        Me.cmdSave = New DevComponents.DotNetBar.ButtonX()
        Me.cmdExit = New DevComponents.DotNetBar.ButtonX()
        Me.GroupPanel1 = New DevComponents.DotNetBar.Controls.GroupPanel()
        Me.GroupPanel1.SuspendLayout()
        Me.SuspendLayout()
        '
        'tbName
        '
        Me.tbName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.tbName.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper
        Me.tbName.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.tbName.Location = New System.Drawing.Point(145, 148)
        Me.tbName.MaxLength = 25
        Me.tbName.Name = "tbName"
        Me.tbName.Size = New System.Drawing.Size(216, 26)
        Me.tbName.TabIndex = 24
        '
        'Label5
        '
        Me.Label5.AutoSize = True
        Me.Label5.BackColor = System.Drawing.Color.Transparent
        Me.Label5.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label5.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label5.Location = New System.Drawing.Point(37, 120)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(45, 18)
        Me.Label5.TabIndex = 22
        Me.Label5.Text = "Name"
        '
        'tbCode
        '
        Me.tbCode.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.tbCode.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper
        Me.tbCode.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.tbCode.Location = New System.Drawing.Point(145, 113)
        Me.tbCode.MaxLength = 10
        Me.tbCode.Name = "tbCode"
        Me.tbCode.Size = New System.Drawing.Size(216, 26)
        Me.tbCode.TabIndex = 23
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.BackColor = System.Drawing.Color.Transparent
        Me.Label1.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label1.Location = New System.Drawing.Point(37, 88)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(40, 18)
        Me.Label1.TabIndex = 41
        Me.Label1.Text = "Code"
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.BackColor = System.Drawing.Color.Transparent
        Me.Label2.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label2.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label2.Location = New System.Drawing.Point(37, 18)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(99, 18)
        Me.Label2.TabIndex = 43
        Me.Label2.Text = "Category Level"
        '
        'Label3
        '
        Me.Label3.AutoSize = True
        Me.Label3.BackColor = System.Drawing.Color.Transparent
        Me.Label3.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label3.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label3.Location = New System.Drawing.Point(37, 53)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(63, 18)
        Me.Label3.TabIndex = 44
        Me.Label3.Text = "Category"
        '
        'cmbLevel
        '
        Me.cmbLevel.DisplayMember = "Text"
        Me.cmbLevel.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed
        Me.cmbLevel.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cmbLevel.ItemHeight = 19
        Me.cmbLevel.Location = New System.Drawing.Point(145, 41)
        Me.cmbLevel.Name = "cmbLevel"
        Me.cmbLevel.Size = New System.Drawing.Size(216, 25)
        Me.cmbLevel.TabIndex = 46
        '
        'cmbWorld
        '
        Me.cmbWorld.DisplayMember = "Text"
        Me.cmbWorld.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed
        Me.cmbWorld.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cmbWorld.ItemHeight = 19
        Me.cmbWorld.Location = New System.Drawing.Point(145, 78)
        Me.cmbWorld.Name = "cmbWorld"
        Me.cmbWorld.Size = New System.Drawing.Size(216, 25)
        Me.cmbWorld.TabIndex = 46
        '
        'cmdSave
        '
        Me.cmdSave.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton
        Me.cmdSave.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdSave.ForeColor = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(64, Byte), Integer))
        Me.cmdSave.Location = New System.Drawing.Point(192, 207)
        Me.cmdSave.Name = "cmdSave"
        Me.cmdSave.Size = New System.Drawing.Size(82, 27)
        Me.cmdSave.TabIndex = 290
        Me.cmdSave.Text = "Save"
        '
        'cmdExit
        '
        Me.cmdExit.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton
        Me.cmdExit.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdExit.ForeColor = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(64, Byte), Integer))
        Me.cmdExit.Location = New System.Drawing.Point(279, 207)
        Me.cmdExit.Name = "cmdExit"
        Me.cmdExit.Size = New System.Drawing.Size(82, 27)
        Me.cmdExit.TabIndex = 289
        Me.cmdExit.Text = "Exit"
        '
        'GroupPanel1
        '
        Me.GroupPanel1.CanvasColor = System.Drawing.SystemColors.Control
        Me.GroupPanel1.ColorSchemeStyle = DevComponents.DotNetBar.eDotNetBarStyle.Office2007
        Me.GroupPanel1.Controls.Add(Me.Label2)
        Me.GroupPanel1.Controls.Add(Me.Label5)
        Me.GroupPanel1.Controls.Add(Me.Label1)
        Me.GroupPanel1.Controls.Add(Me.Label3)
        Me.GroupPanel1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.GroupPanel1.Location = New System.Drawing.Point(0, 0)
        Me.GroupPanel1.Name = "GroupPanel1"
        Me.GroupPanel1.Size = New System.Drawing.Size(415, 265)
        '
        '
        '
        Me.GroupPanel1.Style.BackColor2SchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBackground2
        Me.GroupPanel1.Style.BackColorGradientAngle = 90
        Me.GroupPanel1.Style.BackColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBackground
        Me.GroupPanel1.Style.BorderBottom = DevComponents.DotNetBar.eStyleBorderType.Solid
        Me.GroupPanel1.Style.BorderBottomWidth = 1
        Me.GroupPanel1.Style.BorderColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBorder
        Me.GroupPanel1.Style.BorderLeft = DevComponents.DotNetBar.eStyleBorderType.Solid
        Me.GroupPanel1.Style.BorderLeftWidth = 1
        Me.GroupPanel1.Style.BorderRight = DevComponents.DotNetBar.eStyleBorderType.Solid
        Me.GroupPanel1.Style.BorderRightWidth = 1
        Me.GroupPanel1.Style.BorderTop = DevComponents.DotNetBar.eStyleBorderType.Solid
        Me.GroupPanel1.Style.BorderTopWidth = 1
        Me.GroupPanel1.Style.CornerDiameter = 4
        Me.GroupPanel1.Style.CornerType = DevComponents.DotNetBar.eCornerType.Rounded
        Me.GroupPanel1.Style.TextAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Center
        Me.GroupPanel1.Style.TextColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelText
        Me.GroupPanel1.Style.TextLineAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Near
        Me.GroupPanel1.TabIndex = 291
        Me.GroupPanel1.Text = "Product Category - Add"
        '
        'frmProductCategoryAdd
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(7, 19)
        Me.BackColor = System.Drawing.SystemColors.ActiveCaption
        Me.ClientSize = New System.Drawing.Size(415, 265)
        Me.ControlBox = False
        Me.Controls.Add(Me.cmdSave)
        Me.Controls.Add(Me.cmdExit)
        Me.Controls.Add(Me.cmbWorld)
        Me.Controls.Add(Me.cmbLevel)
        Me.Controls.Add(Me.tbCode)
        Me.Controls.Add(Me.tbName)
        Me.Controls.Add(Me.GroupPanel1)
        Me.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "frmProductCategoryAdd"
        Me.ShowInTaskbar = False
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.GroupPanel1.ResumeLayout(False)
        Me.GroupPanel1.PerformLayout()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

#End Region
    Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
        If ValidateInputData() = True Then
            Dim ICdata As New ICdataLogic
            Try
                If ICdata.CheckProductGroup(CompanyID, tbCode.Text, cmbLevel.SelectedValue) = True Then
                    MsgBox("Group code already exist", MsgBoxStyle.Critical, "Inventory Manager")
                    Exit Sub
                End If
                'Thomas
                Dim Groupname As String
                Dim WorldId As Integer
                WorldId = cmbWorld.SelectedValue
                Groupname = tbName.Text
                If cmbWorld.Enabled = True Then
                    If WorldId > 0 Then
                        Select Case WorldId
                            Case Is = 2276
                                Groupname += " -A"
                            Case Is = 2277
                                Groupname += " -B"
                            Case Is = 2278
                                Groupname += " -E"
                            Case Is = 2279
                                Groupname += " -G"
                            Case Is = 2280
                                Groupname += " -O"
                            Case Is = 2281
                                Groupname += " -P"
                            Case Is = 2282
                                Groupname += " -W"
                            Case Is = 3597
                                Groupname += " -T"
                        End Select
                    End If
                End If
                'Thomas
                ICdata.InsertProductGroup(CompanyID, tbCode.Text, Groupname, cmbLevel.SelectedValue)
                MsgBox("Product Group:" & tbName.Text & " added.", MsgBoxStyle.Information, "Inventory Manager")
                tbName.Text = ""
                tbCode.Focus()
            Catch Ex As Exception
                MsgBox(Ex.ToString, MsgBoxStyle.Critical, "Inventory Manager")
            Finally
                ICdata = Nothing
            End Try
        End If
    End Sub

    Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click
        Me.Close()
        'icg = New ICgroups
        'icg.Show()
        'icg.btnRefresh.PerformClick()
    End Sub

    Private Sub ICgroupsAdd_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LoadLevels()
    End Sub
    Public Sub LoadLevels()
        Dim ICdata As New ICdataLogic
        Dim ds2 As DataSet
        ds2 = ICdata.GetGroupLevels()
        cmbLevel.DataSource = ds2.Tables(0)
        cmbLevel.ValueMember = "LevelID"
        cmbLevel.DisplayMember = "LevelName"
        cmbLevel.SelectedValue = 0
        '
        ds2 = ICdata.GetProductGroups(cmbWorld.SelectedValue, 1)
        cmbWorld.DataSource = ds2.Tables(0)
        cmbWorld.ValueMember = "GroupID"
        cmbWorld.DisplayMember = "GroupName"
        cmbWorld.SelectedValue = 0

        ICdata = Nothing

    End Sub
    Private Function ValidateInputData() As Boolean
        If cmbLevel.SelectedValue = 0 Then
            MsgBox("Select Level", MsgBoxStyle.Critical, "Inventory Manager")
            cmbLevel.Focus()
            Return False
        End If
        If cmbWorld.Enabled = True Then
            If cmbWorld.SelectedValue = 0 Then
                MsgBox("Select World", MsgBoxStyle.Critical, "Inventory Manager")
                cmbWorld.Focus()
                Return False
            End If
        End If
        If tbCode.Text.Trim = "" Then
            MsgBox("Enter Group Code", MsgBoxStyle.Critical, "Inventory Manager")
            tbCode.Focus()
            Return False
        End If
        If tbName.Text.Trim = "" Then
            MsgBox("Enter Group Name", MsgBoxStyle.Critical, "Inventory Manager")
            tbName.Focus()
            Return False
        End If
        Return True
    End Function

    Private Sub ICgroupsAdd_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
        Select Case e.KeyValue
            Case 13
                SendKeys.Send("{Tab}")
            Case 27
                cmdExit.PerformClick()
        End Select

    End Sub

    Private Sub cmbLevel_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If cmbLevel.SelectedIndex > 0 Then
            If cmbLevel.SelectedValue = 4 Then
                Label3.Text = "Department"
                cmbWorld.Enabled = True
            ElseIf cmbLevel.SelectedValue = 5 Then
                Label3.Text = "Department"
                cmbWorld.Enabled = True
            ElseIf cmbLevel.SelectedValue = 6 Then
                Label3.Text = "Department"
                cmbWorld.Enabled = True
            Else
                cmbWorld.Enabled = False
                Label3.Text = "Category"
            End If

        Else
            cmbWorld.Enabled = False
            Label3.Text = "Department"
        End If

    End Sub

    Private Sub cmbWorld_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub
End Class
